﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using CoreEx.Database.Metadata;
using CoreEx.Database.Query;

namespace CoreEx.Database.Linq.Implementation
{
    public class Projectiontarget : IProjectionTarget
    {        
        
        private IDictionary<MemberInfo,string> _memberMap = new Dictionary<MemberInfo, string>();

        public MemberInfo Member { get; set;}

        public string Alias { get; set;}


        public Projectiontarget()
        {
            Children = new List<IProjectionTarget>();            
        }


        public IDictionary<MemberInfo, string> MemberMap
        {
            get { return _memberMap; }
        }

        public ITypeMappingInfo TypeMappingInfo { get; set;}
        public IExpression DbExpression { get; set;}
        public IExpression Projection { get; set;}
        public string[] PrimaryKeyColumnNames { get; set;}
        public IProjectionTarget Parent { get; set;}
        public IList<IProjectionTarget> Children { get; private set; }
        


        public Type GetMemberType()
        {
            Type type;
            var propertyInfo = Member as PropertyInfo;
            if (propertyInfo != null)
                type = propertyInfo.PropertyType;
            else
                type = (Type)Member;
            return type;
        }

        public override string ToString()
        {
            if (TypeMappingInfo != null)
                return TypeMappingInfo.ToString();
            return base.ToString();
        }
    }


    //public class TranslationResult : ITranslationResult
    //{
    //    private IDictionary<MemberInfo, IProjectionTarget> _projectionTargets = new Dictionary<MemberInfo, IProjectionTarget>();
        
    //    public IDictionary<MemberInfo,IProjectionTarget> ProjectionTargets
    //    {
    //        get { return _projectionTargets; }
    //    }
    //}
}
